package PracticasPL.Practica5;

import java.io.IOException;
import java.util.Iterator;
import java.util.List;


import org.antlr.runtime.ANTLRFileStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;

/**
 * Hello world!
 *
 */
public class Procesador 
{
    public static void main( String[] args )
    {
       try {
		AnaFlexLexer lex = new AnaFlexLexer(new ANTLRFileStream(args[0]));
		CommonTokenStream tokens = new CommonTokenStream(lex);
		
		AnaFlexParser parser = new AnaFlexParser(tokens);
		parser.flex();
		if((lex.hasErrors()) || (parser.hasErrors()) )
		{
			System.out.println("Se encotraron errores al analizar");
			 List<RecognitionException> errorsLexer = lex.getAllErrors();
			 List<RecognitionException> errorsParser = parser.getAllErrors();
			 Iterator<RecognitionException> it = errorsLexer.iterator();
			 while(it.hasNext()){
				 System.out.println(it.next());
			 }
			 
			 it = errorsParser.iterator();
			 while(it.hasNext()){
				 System.out.println(it.next());
			 }
				 
		}else
		{
			System.out.println("Fichero procesado correctamente");
		}
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (RecognitionException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
    
    }
}
